#include "cmatrix.h"

CMatrix::CMatrix(float a, float b, float c, float d, float e, float f, float g, float h, float i)
{
	this->mat[0]= a;
	this->mat[1]= b;
	this->mat[2]= c;
	this->mat[3]= d;
	this->mat[4]= e;
	this->mat[5]= f;
	this->mat[6]= g;
	this->mat[7]= h;
	this->mat[8]= i;
}

CMatrix::CMatrix(const CMatrix & M)
{
	this->mat[0]= M.mat[0];
	this->mat[1]= M.mat[1];
	this->mat[2]= M.mat[2];
	this->mat[3]= M.mat[3];
	this->mat[4]= M.mat[4];
	this->mat[5]= M.mat[5];
	this->mat[6]= M.mat[6];
	this->mat[7]= M.mat[7];
	this->mat[8]= M.mat[8];
}

float CMatrix::at(unsigned i)
{
	return this->mat[i];
}

void CMatrix::operator =(const CMatrix & M)
{
	this->mat[0]= M.mat[0];
	this->mat[1]= M.mat[1];
	this->mat[2]= M.mat[2];
	this->mat[3]= M.mat[3];
	this->mat[4]= M.mat[4];
	this->mat[5]= M.mat[5];
	this->mat[6]= M.mat[6];
	this->mat[7]= M.mat[7];
	this->mat[8]= M.mat[8];
}

CMatrix CMatrix::operator*(const CMatrix & M)
{
	return CMatrix( this->at(0)*M.mat[0] + this->at(1)*M.mat[3] + this->at(2)*M.mat[6],/**/ this->at(0)*M.mat[1] + this->at(1)*M.mat[4] + this->at(2)*M.mat[7],/**/ this->at(0)*M.mat[2] + this->at(1)*M.mat[5] + this->at(2)*M.mat[8],
					this->at(3)*M.mat[0] + this->at(4)*M.mat[3] + this->at(5)*M.mat[6],/**/ this->at(3)*M.mat[1] + this->at(4)*M.mat[4] + this->at(5)*M.mat[7],/**/ this->at(3)*M.mat[2] + this->at(4)*M.mat[5] + this->at(5)*M.mat[8],
					this->at(6)*M.mat[0] + this->at(7)*M.mat[3] + this->at(8)*M.mat[6],/**/ this->at(6)*M.mat[1] + this->at(7)*M.mat[4] + this->at(8)*M.mat[7],/**/ this->at(6)*M.mat[2] + this->at(7)*M.mat[5] + this->at(8)*M.mat[8]);
}

CVecteur3f CMatrix::operator*(const CVecteur3f & V)
{
	return CVecteur3f(this->at(0)*V.x + this->at(1)*V.y + this->at(2)*V.z,
					  this->at(3)*V.x + this->at(4)*V.y + this->at(5)*V.z,
					  this->at(6)*V.x + this->at(7)*V.y + this->at(8)*V.z);
}

CPoint3f CMatrix::operator*(CPoint3f & P)
{
	return CPoint3f(this->at(0)*P.GetX() + this->at(1)*P.GetY() + this->at(2)*P.GetZ(),
					this->at(3)*P.GetX() + this->at(4)*P.GetY() + this->at(5)*P.GetZ(),
					this->at(6)*P.GetX() + this->at(7)*P.GetY() + this->at(8)*P.GetZ());
}
